home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
graphics
/
gnuplot
/
contrib
/
green
/
greenps.macros
< prev
Wrap
Internet Message Format
|
1992-11-05
|
16KB
From oliveria%rootbeer.engin.umich.edu@srvr2.engin.umich.edu Mon Aug 17 13:18:10 1992
Return-Path: <oliveria%rootbeer.engin.umich.edu@srvr2.engin.umich.edu>
Received: from srvr2.engin.umich.edu by ra-next.arc.nasa.gov (NeXT-1.0 (From Sendmail 5.52)/NeXT-1.0)
id AA05449; Mon, 17 Aug 92 13:18:05 PDT
Received: from rootbeer.engin.umich.edu by srvr2.engin.umich.edu (5.64/1.35)
id AA12699; Mon, 17 Aug 92 16:31:22 -0400
Received: by rootbeer.engin.umich.edu (5.64/1.35)
id 5a9eb2e98.00251f6; Mon, 17 Aug 92 16:31:19 -0400
Date: Mon, 17 Aug 92 16:31:19 -0400
From: Roque Donizete de Oliveira <oliveria@engin.umich.edu>
Message-Id: <5a9eb2e98.00251f6@rootbeer.engin.umich.edu>
To: woo@ra-next.arc.nasa.gov
Subject: Re: greek symbols in gnuplot
Status: R
I include Martin Green's postscript macros for
font mixing at the end of this message. It might
be a good a idea to try to contact him to see if
there is a newer version (perhaps easier to use and
more similar to LaTeX usage, like using _ and ^).
I'm not sure what is best way of solving this problem.
One could define in the gnudict prologue things like
/\alpha {/Symbol findfont 200 scalefont setfont (a) } def
so that one could say (in gnuplot)
set x label "\alpha"
and get in the postscript file something like
100 100 moveto \alpha show
Now the Symbol font is active and something has to
be done to get back the default font and font size
(one could put everything with a gsave/grestore pair
but then one would have to account for the stringwidth
if doing mixed font stuff). And this doesn't even
include subscripting/superscripting yet.
I like the ability to just use \alpha to get that
symbol. Thus it would be nice to somehow modify
Martin Green's macros to use shortnames like \perp
instead of \136.
It should be relatively straightforward to use Martin Green's
macros as is, if a new set of gnuplot commands, valid only
for the postscript driver, were created. Like
set psxlabel "[string1 sups [string2 string3 subs [{PS S} string4 {PS H}]] string5]"
Perhaps a modifier could be added to the labelling commands.
Like
set xlabel {"<label>"} {<xoff>}{,<yoff>} {ps}
in which case the "ps" would mean the label is to
be passed AS IS to Martin Green's display operator. Thus
set xlabel "[{12 H} (M) subs [{8 S} (a)] (\(x\))]" ps
would create the following postscript code:
100 100 moveto % this varies, of course
[{12 H} (M) subs [{8 S} (a)] (\(x\))] display
and so we have the LaTeX equivalent of $M_{\alpha}(x)$. It
isn't exactly the same for we would be using 12pt Helvetica
to write the "M" and "(x)". I guess it is more like
M${}_{\alpha}$(x)
Anyway, here are the macros:
%
% Procedures for string handling.
%
% From USENET posting in comp.lang.postscript by:
% Martin Green UUCP : ..!torsqnt!ohrd!green
% Ontario Hydro Research Division Telephone: (416)231-4111 Ext7060
% 800 Kipling Ave
% Toronto, Ontario, CANADA, M8Z5S4
%
% Copyright (C) 1990 Martin A. Green
%
% Last edited: Fri Nov 2 09:09:22 EST 1990
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 1, or (at your option)
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
% ----------------------------------------------------------------------
% Text manipulation functions including super- and sub-scripts,
% multiple fonts and sizes, centering and right alignment, and
% full justification.
%
% Example:
%
% [string1 sups [string2 string3 subs string4] {font2} string5] display
%
% should print string1 with the current font, then go into superscript
% mode for string2 and string3, then print string4 as a subscript to
% string3, then return to the original font, followed by a change to font2,
% and finally print string5. The positioning and angle of the printed
% text are determined by the /textalign and /textangle variables.
%
% Font selection: To select Times-Roman 12 point font use: 12 R
%
% Additional notes & changes (C. Towne):
%
% 1. In the above example, to change fonts in the middle of a display,
% but keep the same point size, do something like:
%
% [string1 sups [string2 string3 subs [string4]] {PS S} string5] display
%
% 2. To change fonts in the middle of a display, and change the point size,
% do:
%
% [string1 sups [string2 string3 subs [string4]] {nn S} string5] display
%
% where nn is the desired point size.
%
% 3. To change fonts for a subscript (or superscript) from, say, Helvetica
% to Symbol, do:
%
% [string1 sups [string2 string3 subs [{PS S}string4{PS H}]] string5]
% display
%
% 4. gsave & grestore added to displaywidth procedure. Without it
% entire string would be displayed in last font used.
%
% 5. The /textangle option apparently is missing.
%
% 6. Stuff for centered symbols has been removed.
%
% 7. Procedures displaybbox and displaybbox2 (similar to displaywidth and
% displaywidth2) added.
%
% 8. Font names changed to same as those in troff, and added CB, CO, CD.
%
% 9. Coding style changes made.
%
% Font definitions
/H {dup /PS exch def
/Helvetica findfont exch scalefont setfont} def
/HB {dup /PS exch def
/Helvetica-Bold findfont exch scalefont setfont} def
/HO {dup /PS exch def
/Helvetica-Oblique findfont exch scalefont setfont} def
/HD {dup /PS exch def
/Helvetica-BoldOblique findfont exch scalefont setfont} def
/R {dup /PS exch def
/Times-Roman findfont exch scalefont setfont} def
/B {dup /PS exch def
/Times-Bold findfont exch scalefont setfont} def
/I {dup /PS exch def
/Times-Italic findfont exch scalefont setfont} def
/BI {dup /PS exch def
/Times-BoldItalic findfont exch scalefont setfont} def
/C {dup /PS exch def
/Courier findfont exch scalefont setfont} def
/CB {dup /PS exch def
/Courier-Bold findfont exch scalefont setfont} def
/CO {dup /PS exch def
/Courier-Oblique findfont exch scalefont setfont} def
/CD {dup /PS exch def
/Courier-BoldOblique findfont exch scalefont setfont} def
/S {dup /PS exch def
/Symbol findfont exch scalefont setfont} def
/STRING (a) type cvlit def
/ARRAY [0] type cvlit def
/LEFT -1 def
/CENTRE 0 def
/RIGHT 1 def
/CENTER CENTRE def
/exactwidth 0 def % line added (CET)
/textalign LEFT def % line added (CET)
/fontstore 5 array def
/vshift 5 array def
/fontlevel 0 def
/pushfont {
fontstore exch [ exch PS ] fontlevel exch put
/fontlevel fontlevel 1 add def
} def
/popfont {
0 vshift fontlevel get neg rmoveto
vshift fontlevel 0 put
/fontlevel fontlevel 1 sub def
fontstore fontlevel get aload pop /PS exch def setfont
} def
/sups { % adjust position and reduce font size for superscripts
{currentfont dup pushfont .8 scalefont setfont
vshift fontlevel PS .4 mul put
0 PS .4 mul rmoveto
/PS PS .8 mul def}
} def
/subs { % adjust position and reduce font size for subscripts
{currentfont dup pushfont .8 scalefont setfont
vshift fontlevel PS -.3 mul put
0 PS -.3 mul rmoveto
/PS PS .8 mul def}
} def
/isstring { % return true if argument is a string
type cvlit STRING eq
} def
/isarray { % return true if argument is an array
type cvlit ARRAY eq
} def
%
% compute width of complex text array
%
/displaywidth {
gsave
/textwidth 0 def
/textheight PS def
/fontlevel 0 def
/displevel 0 def
{ % step through array elements
dup isstring {
stringwidth pop /textwidth exch textwidth add def
fontlevel displevel sub 1 eq {popfont} if
} {
dup xcheck {
exec
} {
dup isarray {
displaywidth2
fontlevel displevel sub 1 eq {popfont} if
} { % error handler
pop
} ifelse } ifelse } ifelse
} forall
grestore
} def
/displaywidth2 {
/displevel displevel 1 add def
{ % step through array elements
dup isstring {
stringwidth pop /textwidth exch textwidth add def
fontlevel displevel sub 1 eq {popfont} if
} {
dup xcheck {
exec
} {
dup isarray {
displaywidth2
fontlevel displevel sub 1 eq {popfont} if
} { % error handler
pop
} ifelse } ifelse } ifelse
} forall
/displevel displevel 1 sub def
} def
%
% Compute bounding box of complex text array.
% llx = llx of first character
% urx = current x + width of complete complex text array - right side
% bearing of last character in last string. Right side bearing =
% current x + character width - urx of character bbox.
% lly = min of lly's from each character
% ury = max of ury's from each character
% Note that urx is recomputed for each string in complex text array.
%
/displaybbox {
gsave
% compute dimensions if required
currentpoint 3 -1 roll
/textwidth 0 def
exactwidth 0 ne textalign LEFT ne or
{dup displaywidth} if
% adjust starting position and angle
3 1 roll moveto
textalign LEFT ne {textalign RIGHT eq { textwidth neg 0 rmoveto }
{textwidth 2 div neg 0 rmoveto } ifelse } if
% initialize some stuff
/fontlevel 0 def
/displevel 0 def
/tempstr 1 string def % 1-char string for getting lly and ury
/charn 1 string def
/urx -10000 def % bbox limits
/lly 10000 def
/ury -10000 def
/firstdone false def % flag for "1st. char done?"
% get width of complete complex text array (textwidth)
dup displaywidth
% save current point
currentpoint /ycp exch def /xcp exch def
% loop to step through all array elements
{
% array element is a string
dup isstring {
% get llx from bbox of first char
firstdone not {
dup %stk: string string
gsave
0 1 getinterval %stk: string char1
true charpath flattenpath
pathbbox pop pop pop %stk: string llx
/llx exch def %stk: string
/firstdone true def
grestore
} if
% get urx from current x, width of complete array, and right side
% bearing of last character
dup %stk: string string
gsave
dup length 1 sub get % define string containing last char
charn 0 3 -1 roll put %stk: string
charn stringwidth pop % get width of last char
/cwidth exch def
newpath % get bbox of last char
xcp ycp moveto
charn true charpath flattenpath
pathbbox pop %stk: string llx lly urx
cwidth xcp add exch sub % define right side bearing of last char
/rsb exch def pop pop %stk: string
xcp textwidth add rsb sub % get urx
/urx exch def
grestore
% get lly and ury from bbox of each character
{ % loop over each character in string
gsave
tempstr 0 3 -1 roll %stk: tempstr 0 char
put % put character into tempstr
newpath % get bbox of char
xcp ycp moveto
tempstr true charpath flattenpath
pathbbox %stk: llx lly urx ury
ury amax1 /ury exch def % get ury
exch %stk: llx urx lly
lly amin1 /lly exch def % get lly
pop pop %stk:
grestore
} forall
fontlevel displevel sub 1 eq {popfont} if
} {
% array element is executable
dup xcheck {
exec
} {
% array element is an array
dup isarray {
displaybbox2
fontlevel displevel sub 1 eq {popfont} if
% error
} {
pop
} ifelse } ifelse } ifelse
} forall
llx lly urx ury %stk: llx lly urx ury
grestore
} def
/displaybbox2 {
/displevel displevel 1 add def
% loop to step through all array elements
{
% array element is a string
dup isstring {
% get llx from bbox of first char
firstdone not {
dup %stk: string string
gsave
0 1 getinterval %stk: string char1
true charpath flattenpath
pathbbox pop pop pop %stk: string llx
/llx exch def %stk: string
/firstdone true def
grestore
} if
% get urx from current x, width of complete array, and right side
% bearing of last character
dup %stk: string string
gsave
dup length 1 sub get % define string containing last char
charn 0 3 -1 roll put %stk: string
charn stringwidth pop % get width of last char
/cwidth exch def
newpath % get bbox of last char
xcp ycp moveto
charn true charpath flattenpath
pathbbox pop %stk: string llx lly urx
cwidth xcp add exch sub % define right side bearing of last char
/rsb exch def pop pop %stk: string
xcp textwidth add rsb sub % get urx
/urx exch def
grestore
% get lly and ury from bbox of each character
{ % loop over each character in string
gsave
tempstr 0 3 -1 roll %stk: tempstr 0 char
put % put character into tempstr
newpath % get bbox of char
xcp ycp moveto
tempstr true charpath flattenpath
pathbbox %stk: llx lly urx ury
ury amax1 /ury exch def % get ury
exch %stk: llx urx lly
lly amin1 /lly exch def % get lly
pop pop %stk:
grestore
} forall
fontlevel displevel sub 1 eq {popfont} if
} {
% array element is executable
dup xcheck {
exec
} {
% array element is an array
dup isarray {
displaybbox2
fontlevel displevel sub 1 eq {popfont} if
% error
} {
pop
} ifelse } ifelse } ifelse
} forall
/displevel displevel 1 sub def
} def
%
% display complex text array
%
/display {
currentpoint 3 -1 roll
/textwidth 0 def
exactwidth 0 ne textalign LEFT ne or % compute dimensions if required
{dup displaywidth} if
% adjust starting position and angle
3 1 roll moveto
textalign LEFT ne {textalign RIGHT eq { textwidth neg 0 rmoveto }
{textwidth 2 div neg 0 rmoveto } ifelse } if
% print text
/fontlevel 0 def
/displevel 0 def
{ % step through array elements
dup isstring {
show
fontlevel displevel sub 1 eq {popfont} if
} {
dup xcheck {
exec
} {
dup isarray {
display2
fontlevel displevel sub 1 eq {popfont} if
} { % error handler
pop
} ifelse } ifelse } ifelse
} forall
} def
/display2 {
/displevel displevel 1 add def
{ % step through array elements
dup isstring {
show
fontlevel displevel sub 1 eq {popfont} if
} {
dup xcheck {
exec
} {
dup isarray {
display2
fontlevel displevel sub 1 eq {popfont} if
} { % error handler
pop
} ifelse } ifelse } ifelse
} forall
/displevel displevel 1 sub def
} def